<template>
  <div v-show="props.compType === 'colorPicker'">
    <el-form-item label="ID">
      <el-tooltip
        class="item"
        effect="dark"
        content="请注意,ID的修改可能会导致该组件相关事件失效！"
        placement="left"
      >
        <el-input class="input" v-model="props.id" @change="handlerChangeGetId"></el-input>
      </el-tooltip>
    </el-form-item>
    <el-form-item label="显示标签">
      <el-switch v-model="props.showLabel" @change="handlerShowLabel"></el-switch>
    </el-form-item>
    <el-form-item label="标签文字" v-show="props.showLabel">
      <el-input class="input" v-model="props.label"></el-input>
    </el-form-item>
    <el-form-item label="标签长度" v-show="props.showLabel">
      <el-input-number v-model="props.labelWidth" :min="1" :max="200"></el-input-number>
    </el-form-item>
    <el-form-item label="默认颜色">
      <el-color-picker v-model="props.modelValue" />
    </el-form-item>
    <el-form-item label="禁用">
      <el-switch v-model="props.disabled"></el-switch>
    </el-form-item>
    <el-form-item label="大小">
      <el-radio-group v-model="props.size">
        <el-radio-button value="large">大</el-radio-button>
        <el-radio-button value="default">中</el-radio-button>
        <el-radio-button value="small">小</el-radio-button>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="预定义颜色">
      <div class="select-item" v-for="(item, index) in props.predefine" :key="item">
        <span class="el-color-picker__color"
          ><!--style="background-color: rgb(64, 158, 255);"-->
          <span class="el-color-picker__color-inner" :style="{ 'background-color': item }"> </span>
        </span>
        <div class="close-btn select-line-icon">
          <i class="el-icon-remove-outline" @click="handlerRemoveColor(index)" />
        </div>
      </div>
      <br />
      <el-color-picker v-model="color" @change="handlerAddPreColor"></el-color-picker>
    </el-form-item>
  </div>
</template>
<script lang="ts">
import { Component, Prop } from 'web-decorator-vue';
import { changeId, type FormDesignerMixin } from '../mixin/FormDesignerMixin';

/**
 *
 */
@Component({
  name: 'color-picker-config',
  mixins: [changeId]
})
export default class ColorPicker implements FormDesignerMixin {
  /**
   * 参数
   */
  @Prop() props!: any;
  /**
   * 颜色
   */
  color: string = '#409EFF';
  /**
   * mixins 会自动注入函数
   */
  // 数据属性
  handlerChangeIdCallback?: Function;
  
  // 方法
  handlerChangeGetId(val: any) {
    if (this.handlerChangeIdCallback) {
      this.handlerChangeIdCallback(val);
    }
  }

  // TODO 补齐作用
  /**
   *
   * @param val
   */
  handlerShowLabel(val: any) {
    this.props.labelWidth = val ? 80 : 0;
  }

  // TODO 补齐作用
  /**
   *
   * @param val
   */
  handlerAddPreColor(val: any) {
    console.log(val);
    this.props.predefine.push(val);
    console.log(this.props.predefine);
  }
  // TODO 补齐作用
  /**
   * @param index
   */
  handlerRemoveColor(index: any) {
    this.props.predefine.splice(index, 1);
  }
}
</script>
<style scoped>
.el-color-picker__color {
  position: relative;
  display: block;
  box-sizing: border-box;
  border: 1px solid #999;
  border-radius: 2px;
  width: 100px;
  height: 30px;
  float: left;
  margin-right: 2px;
}
</style>
